package com.anjie.powerproject.repository;

import com.anjie.powerproject.entity.StationInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface StationInfoRepository extends JpaRepository<StationInfo,Integer> {

    List<StationInfo> findStationInfosByStationName(String stationName);
    @Transactional
    void deleteStationInfoByStationName(String stationName);

    StationInfo findStationInfoById(Integer id);

    @Query(nativeQuery = true, value = "select * from station_info limit 1")
    StationInfo findStationInfoLimitFirst();

    @Query(value = "update station_info SET station_name = ?1,station_area = ?2,building_area = ?3,construction_year = ?4,station_adress = ?5,city_code = ?6,battery_code = ?7,battery_point_id= ?8,energy_code = ?9,energy_point_id= ?10 where id = ?11",nativeQuery = true)
    @Modifying
    @Transactional
    void updateStationInfo(String stationName,String stationArea,String buildingArea,String constructionYear,String stationAdress,String cityCode,String batteryCode,Integer batteryPointId,String energyCode,Integer energyPointId,Integer id);


}
